package leetcode;

/**
 * 题目：有效的括号
 * 链接：https://leetcode.cn/problems/valid-parentheses/description/
 */

import java.util.Scanner;
import java.util.Stack;

public class BracketIsValid {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String bracketStr = sc.nextLine();
        boolean valid = isValid(bracketStr);
        System.out.println(valid ? "YES" : "NO");
    }
    public static boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for(char c : s.toCharArray()){
            if(c == '('){
                stack.push(')');
            }else if(c == '['){
                stack.push(']');
            }else if(c == '{'){
                stack.push('}');
            }else if(stack.isEmpty() || c != stack.pop()){
                return false;
            }
        }
        return stack.isEmpty();
    }
}
